package com.itlong.cloud.commons;

import com.itlong.cloud.iottp.IIotDeviceOnlineServiceClient;
import com.itlong.cloud.utils.date.DateUtil;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

/**
 * <desc>
 *      设备在线定时任务
 * </desc>
 *
 * @createDate 2019/07/03
 */
@EnableScheduling // 启用定时任务
@RestController
public class DeviceOnlineTimeTask {

    private static Logger LOG = LoggerFactory.getLogger(DeviceOnlineTimeTask.class);

    @Autowired
    private IIotDeviceOnlineServiceClient iIotDeviceOnlineServiceClient;

    /**
     * <desc>
     *      同步业务指令至响应硬件结果表
     * </desc>
     *
     * @author Qiang.S
     * @creatDate 2019/07/03
     */
    @Scheduled(cron = "0 */1 * * * ?") // 每1分钟执行一次
    public void timeTaskPushCloudEntrance() {
        try {
            iIotDeviceOnlineServiceClient.timeTaskMaintenanceOnline();
        }catch (Exception e){
            LOG.error("【定时任务】维护在线设备执行失败，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"),e);
        }
    }

    /**
     * <desc>
     *      同步业务指令至响应硬件结果表
     * </desc>
     *
     * @author caoshuai
     * @creatDate 2020/09/24
     */
    @Scheduled(cron = "0 */2 * * * ?") // 每2分钟执行一次
    public void timeTaskHWPushCloudEntrance() {
        try {
            iIotDeviceOnlineServiceClient.timeTaskHWMaintenanceOnline();
        }catch (Exception e){
            LOG.error("【定时任务】维护在线设备执行失败，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"),e);
        }
    }

}
